package top.kaoshanji.q1ch07a.config;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import top.kaoshanji.q1ch07a.web.WebConfig;

import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletRegistration;

/**
 * 配置DispatcherServlet
 * @author kaoshanji
 * ^_^
 * create time 2025/4/25 10:21
 */
public class SpitterWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[] {RootConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[] {WebConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] {"/"};
    }

    // 配置 MultipartResolver 参数
    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic registration) {
        String multipartPath = "G:\\Code-Learn-Project\\back-Spring全家桶-SpringFramework1\\can2024122433-version1\\q1-ch07a-Spittr\\uploads\\";
        // 文件大小是以字节为单位
        // 文件大小不能超过 2MB，整个请求不超过 4MB
        registration.setMultipartConfig(new MultipartConfigElement(multipartPath, 2097152, 4194304, 0));
    }



}
